import { Router } from '@adonisjs/core/http'
import { Constructor, LazyImport } from '@adonisjs/core/types/http'

Router.macro('curd', function (this: Router, pattern, controller) {
  const ctr = controller as any

  this.post(`${pattern}/create`, [ctr, 'create'])
  this.get(`${pattern}/detail`, [ctr, 'detail'])
  this.get(`${pattern}/list`, [ctr, 'list'])
  this.route(`${pattern}/update/:id`, ['PUT', 'PATCH'], [ctr, 'update'])
  this.delete(`${pattern}/delete`, [ctr, 'delete'])
})

declare module '@adonisjs/core/http' {
  export interface Router {
    curd: <T extends Constructor<any>>(path: string, controller: LazyImport<T>) => void
  }
}
